<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>施工难度设置</title>
		<link rel="stylesheet" type="text/css" href="../static/common.css"/>
		<link rel="stylesheet" type="text/css" href="static/css/asscom.css"/>
		<link rel="stylesheet" type="text/css" href="static/css/index.css"/>

	</head>
	<body>
		<!-- right -->
		<div class="rightBox">

			<div class="nav1 clearfix">
				<a href="gradeconfig.html" class="btnAct1">等级分数</a>
				<a href="valueconfig.html" class="btnAct1">产值系数</a>
				<a href="scaleconfig.html" class="btnAct1">规模分数</a>
				<a href="numberconfig.html" class="btnAct1">参评个数</a>
				<a href="specialconfig.html" class="btnAct1">特殊项目</a>
				<a href="difficultconfig.html" class="active btnAct1">施工难度</a>
				<a href="typeconfig.html" class="btnAct1">队伍类型</a>
			</div>
			<div class="config clearfix">
					<!-- 评分等级 -->
					<div class="conTable fl" id="grade">
						<h3>施工难度分数设置 <span class="helpFont" id="helpFont" title="点击查看说明及帮助"></span></h3>
						<span class="err"></span>
							<div id="helpContext" class="helpContext">
							<p>产值系数只能为非负数，并且精确小数后8位 注！(正常产值，近三年系数，之前年份系数为系统工作必有的参数，请勿随意操作)</p>
						</div>
						<table>
							<thead>
								<tr>
									<th>作业难度名称</th>
									<th>分数</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody>
								
							</tbody>
						</table>
					</div>
	
			</div>
		</div>
	</body>
</html>
<script src="../static/js/jquery-1.8.3.js" type="text/javascript" charset="utf-8"></script>
<script src="../static/dx.js" type="text/javascript" charset="utf-8"></script>
<!-- <script src="static/js/common.js" type="text/javascript" charset="utf-8"></script> -->
<script type="text/javascript">
	$(document).ready(function(){
		domAjax();
	
		
	})
	//默认加载
	function domAjax(){
		DX.ajax_method({
			'type':'GET',
			'url':'/eva/dlc/findPartAll',
			'param':{},
			'callBack':tableCall
		})
	}
	// 渲染回调
	function tableCall(res){
		 
		console.log(res);
		if(res.code !='200'){console.log('没有数据');return;}
			
		var grade = '';//评分等级
		if(res.data.length != 0 && res.data != null){
			// grade = each(res.data[1]);
			$.each(res.data,function(i,val){
				grade += '<tr id="'+val.partid+'">';
				grade += "<td class='clum1'><input value="+val.part_name+" class='tableEdit' /></td>";
				grade += "<td class='clum2'><input value="+val.score+" class='tableEdit' /></td>";
				grade += "<td id='"+val.partid+"'><span class='mod1'>修改</span><span class='del1'>删除</span></td>";
				grade += '</tr>';
			})
		}
		$('#grade table tbody').html(grade+end1());
		// $('#grade tbody tr').click(function(){
		// 	DX.clickTr($(this),['input']);			
		// })
		//修改
		$('.mod1').click(function(){
			mod($(this),'/eva/dlc/updatePart');
		})
		//删除
		$('.del1').click(function(){
			del($(this),'/eva/dlc/deletePart');
		})
		//新增
		$('.inset1').click(function(){
			inset($(this),'/eva/dlc/insertPart');
		})
		
	}
	//table的添加
	function end1(id){
		return '<tr ><td class="clum1"><input type="text" value="" class="tableEdit" /></td><td class="clum2"><input type="text" class="tableEdit" value="" /></td><td><span class="inset1">添加</span></td></tr>';
	}
	/* 修改
	* obj 当前元素$(this)
	* url 接口地址
	*/
	function mod(obj,url){
		$('.err').hide();
		var id = obj.parent().attr('id');
		var name = obj.parent().siblings('.clum1').find('input').val();
		var value = obj.parent().siblings('.clum2').find('input').val();
		
		var res = {'partid':id,'part_name':name,'score':value};
	
		var isname = DX.isNull(name);
		if(isname){
			obj.parents('.conTable').find('.err').show();
			obj.parents('.conTable').find('.err').html('作业难度名称');return;
		}
		var isvalueN = DX.isNull(value);
		if(isvalueN){
			
			obj.parents('.conTable').find('.err').show();
			obj.parents('.conTable').find('.err').html('分数不能为空');return;
		}
		var isvalue = DX.isInt(value);
		if(!isvalue){
			obj.parent().siblings('.clum2').find('input').val('');
			obj.parents('.conTable').find('.err').show();
			obj.parents('.conTable').find('.err').html('分数只能为正整数');return;
		}
				
		
		DX.ajax_method({
			'type':'POST',
			'url':url,
			'param':res,
			'change':obj[0],
			'callBack':function(res){
				// console.log(res);
				if(res.code != '200'){
					obj.parents('.conTable').find('.err').show();
					obj.parents('.conTable').find('.err').html(res.msg);
				}
			}
		})
	}
	/* 删除
	* obj 当前元素$(this)
	* url 接口地址
	*/
	function del(obj,url){
		$('.err').hide();
		var sub = confirm('确认删除');
		
		if(!sub) return;
		var id = obj.parent().attr('id');
		var param = {'partid':id};
		// console.log(param);return;
		DX.ajax_method({
			'type':'POST',
			'url':url,
			'param':param,
			'change':obj[0],
			'callBack':function(res){
				console.log(res);
				if(res.code != '200'){
					obj.parents('.conTable').find('.err').show();
					obj.parents('.conTable').find('.err').html(res.msg);
				}else{
					domAjax();
				}
			}
		})
	}
	/* 新增
	* obj 当前元素$(this)
	* url 接口地址
	*/
	function inset(obj,url){
		$('.err').hide();
		var name = obj.parent().siblings('.clum1').find('input').val();
		var value = obj.parent().siblings('.clum2').find('input').val();
		
		var res = {'part_name':name,'score':value};

		var isname = DX.isNull(name);
		if(isname){
			obj.parents('.conTable').find('.err').show();
			obj.parents('.conTable').find('.err').html('类别不能为空');return;
		}
			
		var isvalueN = DX.isNull(value);
		if(isvalueN){
			obj.parents('.conTable').find('.err').show();
			obj.parents('.conTable').find('.err').html('分数不能为空');return;
		}
		if(value != 0){
			var isvalue = DX.isInt(value);
			if(!isvalue){
				obj.parent().siblings('.clum2').find('input').val('');
				obj.parents('.conTable').find('.err').show();
				obj.parents('.conTable').find('.err').html('分数只能为正整数');return;
			}
		}
		
	
		DX.ajax_method({
			'type':'POST',
			'url':url,
			'param':res,
			'change':obj[0],
			'callBack':function(res){
				if(res.code != '200'){
					obj.parents('.conTable').find('.err').show();
					obj.parents('.conTable').find('.err').html(res.msg);
				}else{
					domAjax();
				}
			}
		})
	}
</script>
